using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class JobSeekers_experience : System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
             WebConfigurationManager.ConnectionStrings[
               "RecruitVietnam"].ConnectionString;
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            string experienceID = 
            Request.QueryString.Get("ExperienceID");
            if (!IsPostBack)
            {
                Common cls = new Common(connectionString);
                DataSet dataSet = cls.GetDataSet(
                "Select * from tblJobCategories;" +
                "Select * from tblProvinces"
                 );
                DropDownListHelper helper = 
                new DropDownListHelper();
                helper.FillDataTableToDropDownList(
                dataSet, new DropDownList[2] { 
                ddlDepartment, ddlProvince },
                new string[2] { "JobCategoryName", 
                "ProvinceName" }, new string[2] { 
                "JobCategoryID", "ProvinceID" }, 
                new string[2] { "", "" });
                EditExperience(experienceID);
            }
        }
    }
     
    void EditExperience(string experienceID)
    {
        if (experienceID != "" && experienceID != null)
        {
            SqlServerProvider cls = new 
            SqlServerProvider(connectionString);
            cls.CommandText = 
            "select * from tblJSExperiences" +
            " where UserID=@UserID and"+
            " ExperienceID= @ExperienceID ";
            cls.ParameterCollection = new 
            string[2] { "@UserID", "@ExperienceID" };
            cls.ValueCollection = new string[2] 
            { Session["jsuserid"].ToString(), 
            experienceID };

            DataRow dataRow =
            cls.GetDataRow();
            if (dataRow != null)
             {
                ExperienceID.Value = 
                dataRow[0].ToString();
                txtCompany.Text = dataRow[2].ToString();
                txtAddress.Text = dataRow[3].ToString();
                ddlProvince.SelectedValue = 
                dataRow[4].ToString();
                ddlCountry.SelectedValue = 
                dataRow["Nationality"].ToString();
                ddlDepartment.SelectedValue = 
                dataRow[6].ToString();
                txtPosition.Text = 
                dataRow[7].ToString();          
                txtFrom.Text = dataRow[8].ToString();
                txtTo.Text = dataRow[9].ToString();
                txtSalary.Text = dataRow[10].ToString();
                txtSummary.Text = dataRow[11].ToString();            
                txtDescription.Text = 
                dataRow[12].ToString();
                btnSave.Text = "Update";
                btnMore.Visible = false;
             }
        }
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {        
            Response.Redirect("skills.aspx");
        
    }
    void Save(string id)
    {
        RecruitVietnam cls = new RecruitVietnam();
        cls.ConnectionString = connectionString;
        if (!cls.AddNewOrUpdateExperience(
        id, Convert.ToString(
        Session.Contents["jsuserid"]),
        txtCompany.Text, txtAddress.Text,
        ddlProvince.SelectedValue,
        ddlCountry.SelectedValue,
        ddlDepartment.SelectedValue,
        txtSummary.Text,
        txtPosition.Text, txtSalary.Text,
        txtFrom.Text, txtTo.Text,
        txtDescription.Text))
            literalError.Text = "Error: "
            + cls.ErrorMessage;
    }
    protected void btnMore_Click(object sender, EventArgs e)
    {
        Save("0");
        Response.Redirect("experience.aspx");
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string id="0";
        if (ExperienceID.Value != "")
            id=ExperienceID.Value;
        Save(id); 
        if (ExperienceID.Value != "")
            Response.Redirect("experiences.aspx");
        else
            Response.Redirect("experience.aspx");
    }
}
